undefined reference to `trunc'

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Giulio

    #1

    undefined reference to `trunc'

    I can't understand where is the problem:
    this is the file I would like to compile
    ------------------------
    #include <math.h>
    #include <stdlib.h>

    int main (){
    int c = trunc(17.5);
    return c;
    }
    --------------------------

    with this command:
    --------------------
    gcc -o prova prova.c
    ----------------------------
    and this is the error the compiler gives me.

    -----------------------------
    /tmp/cc0ZzTZJ.o: In function `main':
    /tmp/cc0ZzTZJ.o(.tex t+0x32): undefined reference to `trunc'
    collect2: ld returned 1 exit status
    ------------------------------------------------
  • S.Tobias

    #2
    Re: undefined reference to `trunc'

    Giulio <frank.zappalEV A@email.it.inva lid> wrote:[color=blue]
    > this is the file I would like to compile
    > ------------------------
    > #include <math.h>[/color]
    [snip][color=blue]
    > --------------------------[/color]
    [color=blue]
    > with this command:
    > --------------------
    > gcc -o prova prova.c[/color]

    gcc -o prova prova.c -lm

    man gcc
    [color=blue]
    > ----------------------------
    > and this is the error the compiler gives me.[/color]

    strictly: it's from the linker
    [color=blue]
    > -----------------------------
    > /tmp/cc0ZzTZJ.o: In function `main':
    > /tmp/cc0ZzTZJ.o(.tex t+0x32): undefined reference to `trunc'
    > collect2: ld returned 1 exit status[/color]
    ^^[color=blue]
    > ------------------------------------------------[/color]

    --
    Stan Tobias
    mailx `echo siXtY@FamOuS.Be dBuG.pAlS.INVALID | sed s/[[:upper:]]//g`

    Comment

    • Bjørn Augestad

      #3
      Re: undefined reference to `trunc'

      Giulio wrote:
      [color=blue]
      > I can't understand where is the problem:
      > this is the file I would like to compile
      > ------------------------
      > #include <math.h>
      > #include <stdlib.h>
      >
      > int main (){
      > int c = trunc(17.5);
      > return c;
      > }
      > --------------------------
      >
      > with this command:
      > --------------------
      > gcc -o prova prova.c[/color]

      Try gcc -o prova prova.c -lm
      where m is for the math library and the l is the letter ell.

      HTH
      Bjørn

      Comment

      • Keith Thompson

        #4
        Re: undefined reference to `trunc'

        Giulio <frank.zappalEV A@email.it.inva lid> writes:
        [...][color=blue]
        > -----------------------------
        > /tmp/cc0ZzTZJ.o: In function `main':
        > /tmp/cc0ZzTZJ.o(.tex t+0x32): undefined reference to `trunc'
        > collect2: ld returned 1 exit status
        > ------------------------------------------------[/color]

        This is question 14.3 in the C FAQ,
        <http://www.eskimo.com/~scs/C-faq/top.html>.

        --
        Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
        San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
        We must do something. This is something. Therefore, we must do this.

        Comment

        • jacob navia

          #5
          Re: undefined reference to `trunc'

          Bjørn Augestad wrote:
          [color=blue]
          > Giulio wrote:
          >[color=green]
          >> I can't understand where is the problem:
          >> this is the file I would like to compile
          >> ------------------------
          >> #include <math.h>
          >> #include <stdlib.h>
          >>
          >> int main (){
          >> int c = trunc(17.5);
          >> return c;
          >> }
          >> --------------------------
          >>
          >> with this command:
          >> --------------------
          >> gcc -o prova prova.c[/color]
          >
          >
          > Try gcc -o prova prova.c -lm
          > where m is for the math library and the l is the letter ell.
          >
          > HTH
          > Bjørn
          >[/color]

          Ahhh couldn't gcc include the math lib by default?????

          The few microseconds that this would cost in modern machines
          would be *really* justified by the easier user interface.

          This is a relic of the old days when machines were so slow that
          including or not the math lib made a difference in link time.

          Today, this is completely obsolete.

          jacob

          Comment

          • Jack Klein

            #6
            Re: undefined reference to `trunc'

            On Wed, 24 Nov 2004 22:25:18 +0100, jacob navia
            <jacob@jacob.re mcomp.fr> wrote in comp.lang.c:
            [color=blue]
            > Bjørn Augestad wrote:
            >[color=green]
            > > Giulio wrote:
            > >[color=darkred]
            > >> I can't understand where is the problem:
            > >> this is the file I would like to compile
            > >> ------------------------
            > >> #include <math.h>
            > >> #include <stdlib.h>
            > >>
            > >> int main (){
            > >> int c = trunc(17.5);
            > >> return c;
            > >> }
            > >> --------------------------
            > >>
            > >> with this command:
            > >> --------------------
            > >> gcc -o prova prova.c[/color]
            > >
            > >
            > > Try gcc -o prova prova.c -lm
            > > where m is for the math library and the l is the letter ell.
            > >
            > > HTH
            > > Bjørn
            > >[/color]
            >
            > Ahhh couldn't gcc include the math lib by default?????
            >
            > The few microseconds that this would cost in modern machines
            > would be *really* justified by the easier user interface.
            >
            > This is a relic of the old days when machines were so slow that
            > including or not the math lib made a difference in link time.
            >
            > Today, this is completely obsolete.
            >
            > jacob[/color]

            Yes, of course, but this comes from the *NIX world, where the gurus
            will NEVER give up their advantage over newbies. They want the
            newcomers to come groveling to their betters.

            --
            Jack Klein
            Home: http://JK-Technology.Com
            FAQs for
            comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
            comp.lang.c++ http://www.parashift.com/c++-faq-lite/
            alt.comp.lang.l earn.c-c++

            Comment

            • Jens.Toerring@physik.fu-berlin.de

              #7
              Re: undefined reference to `trunc'

              Jack Klein <jackklein@spam cop.net> wrote:[color=blue]
              > On Wed, 24 Nov 2004 22:25:18 +0100, jacob navia
              > <jacob@jacob.re mcomp.fr> wrote in comp.lang.c:[color=green][color=darkred]
              >> >> with this command:
              >> >> --------------------
              >> >> gcc -o prova prova.c
              >> >
              >> >
              >> > Try gcc -o prova prova.c -lm
              >> > where m is for the math library and the l is the letter ell.
              >> >
              >> > HTH
              >> > Bjørn
              >> >[/color]
              >>
              >> Ahhh couldn't gcc include the math lib by default?????
              >>
              >> The few microseconds that this would cost in modern machines
              >> would be *really* justified by the easier user interface.
              >>
              >> This is a relic of the old days when machines were so slow that
              >> including or not the math lib made a difference in link time.
              >>
              >> Today, this is completely obsolete.
              >>
              >> jacob[/color][/color]
              [color=blue]
              > Yes, of course, but this comes from the *NIX world, where the gurus
              > will NEVER give up their advantage over newbies. They want the
              > newcomers to come groveling to their betters.[/color]

              Aren't you a bit harsh here? I guess it got more to do with the fact
              that there are that many different implementations of UNIX that it
              takes a lot longer for such changes to get adopted by everyone. That's
              quite a bit more difficult than in a world where you have a single
              company that can tell everyone how to do things and rewrite every-
              thing you have because they decided to do things differently without
              having to get a consensus.
              Regards, Jens
              --
              \ Jens Thoms Toerring ___ Jens.Toerring@p hysik.fu-berlin.de
              \______________ ____________ http://www.toerring.de

              Comment

              • Dave Vandervies

                #8
                Re: undefined reference to `trunc'

                In article <30nbbnF2uuj0pU 2@uni-berlin.de>,
                <Jens.Toerring@ physik.fu-berlin.de> wrote:[color=blue]
                >Jack Klein <jackklein@spam cop.net> wrote:[/color]
                [color=blue][color=green]
                >> Yes, of course, but this comes from the *NIX world, where the gurus
                >> will NEVER give up their advantage over newbies. They want the
                >> newcomers to come groveling to their betters.[/color]
                >
                >Aren't you a bit harsh here? I guess it got more to do with the fact
                >that there are that many different implementations of UNIX that it
                >takes a lot longer for such changes to get adopted by everyone. That's
                >quite a bit more difficult than in a world where you have a single
                >company that can tell everyone how to do things and rewrite every-
                >thing you have because they decided to do things differently without
                >having to get a consensus.[/color]

                Jack may be being too harsh, but you're being too generous, so it
                balances out.

                Unix culture has a "It works this way, it's worked this way for a long
                time, why waste energy changing it?" attitude that assumes easy access
                to the corresponding oral tradition and causes problems without that.

                "You know that now, so we still don't need to change it" tends to work a
                lot better when everybody can go visit the guru down the hall than when
                people are trying to learn it on their own.


                dave

                --
                Dave Vandervies dj3vande@csclub .uwaterloo.ca

                Right now? Either. Just fly out on your pig and buy one.
                --Nick Maclaren in comp.arch

                Comment

                Working...